package com.smartwasser.yunhtgl.apphtgl.pager;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.donkingliang.banner.CustomBanner;
import com.smartwasser.yunhtgl.apphtgl.R;
import com.smartwasser.yunhtgl.apphtgl.activity.CaseActivity;
import com.smartwasser.yunhtgl.apphtgl.activity.SP2Activity;
import com.smartwasser.yunhtgl.apphtgl.base.BasePager;
import com.smartwasser.yunhtgl.apphtgl.presenter.HPagerPresenter;
import com.smartwasser.yunhtgl.apphtgl.presenter.HPagerPresenterImpl;
import com.smartwasser.yunhtgl.apphtgl.view.HPagerView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.smartwasser.yunhtgl.apphtgl.widget.CustomToast.showToast;

/**
 * 首页---合同服务管理系统
 */
public class HPager extends BasePager implements HPagerView {
    private HPagerPresenter mHPagerPresenter = new HPagerPresenterImpl(this);
    private Intent intent;
    @BindView(R.id.banner)
    CustomBanner<String> mBanner;

    public HPager(Context context) {
        super(context);
    }

    @Override
    public View initView() {
        view = View.inflate(context, R.layout.activity_page_h, null);
        ButterKnife.bind(this, view);
        initData();
        return view;
    }

    @Override
    public void initData() {
        mHPagerPresenter.getBannerImage();
    }

    @OnClick({R.id.h_sp, R.id.h_ba})
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.h_sp:
                intent = new Intent(context, SP2Activity.class);
                context.startActivity(intent);
                break;
            case R.id.h_ba:
                intent = new Intent(context, CaseActivity.class);
                context.startActivity(intent);
//                showToast(context, "此功能暂未开放");
                break;
        }

    }

    @Override
    public void updateBanner(ArrayList<String> images) {
        mBanner.setPages(new CustomBanner.ViewCreator<String>() {
            @Override
            public View createView(Context context, int position) {
                ImageView imageView = new ImageView(context);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                return imageView;
            }

            @Override
            public void updateUI(Context context, View view, int position, String s) {
                Picasso.with(context).load(Integer.parseInt(s)).into((ImageView) view);
            }


        }, images).setScrollDuration(150).startTurning(5000);
    }
}
